﻿using System;
using System.IO;
using System.Runtime.InteropServices;

namespace SystemModule
{
    /// <summary>
    /// 人物技能
    /// </summary>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public class THumMagic
    {
        /// <summary>
        /// 技能ID
        /// </summary>
        public ushort wMagIdx;
        /// <summary>
        /// 等级
        /// </summary>        
        public byte btLevel;
        /// <summary>
        /// 技能快捷键
        /// </summary>        
        public byte btKey;
        public int nTranPoint;

        public THumMagic()
        { 
        
        }

        public THumMagic(byte[] buff)
        {
            this.wMagIdx = BitConverter.ToUInt16(buff, 0);
            this.btLevel = (byte)BitConverter.ToInt16(buff, 2);
            this.btKey = (byte)BitConverter.ToInt16(buff, 3);
            this.nTranPoint = BitConverter.ToInt32(buff, 4);
        }

        public byte[] ToByte()
        {
            using (var memoryStream = new MemoryStream())
            {
                var backingStream = new BinaryWriter(memoryStream);
                backingStream.Write(wMagIdx);
                backingStream.Write(btLevel);
                backingStream.Write(btKey);
                backingStream.Write(nTranPoint);

                var stream = backingStream.BaseStream as MemoryStream;
                return stream.ToArray();
            }
        }
    }
}